# coding:utf-8
from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin


# Create your models here.
class Property(models.Model):
    name = models.CharField(u'宴会性质',max_length=16)
    class Meta:
        verbose_name = u'宴会性质'
        verbose_name_plural = u'宴会性质'
    def __unicode__(self):
        return self.name

class Brand(models.Model):
    name = models.CharField(u'品牌',max_length=32)
    class Meta:
        verbose_name = u'品牌'
        verbose_name_plural = u'品牌'
    def __unicode__(self):
        return self.name
class Gender(models.Model):
    name = models.CharField(u'性别',max_length=8)
    class Meta:
        verbose_name = u'性别'
        verbose_name_plural = u'性别'
    def __unicode__(self):
        return self.name

class SaleMan(models.Model):
    name = models.CharField(u'姓名',max_length=16)
    jobNumber = models.CharField(u'员工号',max_length=16)
    phoneNumber = models.CharField(u'手机号码',max_length=11)
    gender = models.ForeignKey(Gender) #性别
    user = models.ForeignKey(User)
    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = u'销售人员'
        verbose_name_plural = u'销售人员'

class Status(models.Model):
    name = models.CharField(u'订单状态',max_length=16)
    class Meta:
        verbose_name = u'订单状态'
        verbose_name_plural = u'订单状态'
    def __unicode__(self):
        return self.name

class Client(models.Model):
    name = models.CharField(u'姓名',max_length=16)
    phone = models.CharField(u'电话',max_length=11)
    email = models.EmailField(u'邮箱',blank=True,null=True)
    class Meta:
        verbose_name = u'委托人'
        verbose_name_plural = u'委托人管理'
    def __unicode__(self):
        return self.name
class Order(models.Model):
    orderID = models.CharField(u'订单号',primary_key=True,max_length=20)
    brand = models.ForeignKey(Brand,blank=True,null=True)#承办方
    status = models.ForeignKey(Status) # 订单状态
    orderTime = models.DateField(u'预约时间')
    signTime = models.DateField(u'签约时间',blank=True,null=True)
    party_nature = models.ForeignKey(Property) #宴会性质
    role1 = models.CharField(u'主角1',max_length=16)
    role2 = models.CharField(u'主角2',max_length=16,blank=True,null=True)
    weddingAddress = models.CharField(u'结婚地址',blank=True,max_length=100,null=True)
    weddingTime = models.DateField(u'结婚时间',blank=True,null=True)
    answerDoorTime = models.DateField(u'回门时间',blank=True,null=True)
    answerDoorAddress = models.CharField(u'回门地址',blank=True,max_length=100,null=True)
    saleman = models.ForeignKey(SaleMan) # 负责人
    client = models.ForeignKey(Client) #委托人
    theme = models.CharField(u'主题',max_length=200,blank=True,null=True)
    hue = models.CharField(u'色调',max_length=8,blank=True,null=True)
    price = models.IntegerField(u'全款',blank=True,null=True)
    advancePay = models.IntegerField(u'预付款')
    finalPay = models.IntegerField(u'尾款',blank=True,null=True)
    signImage = models.URLField(u'数字签名',blank=True,null=True)

    backReason = models.CharField(u'退款原因',max_length=200,blank=True,null=True)
    lessReason = models.CharField(u'未结尾款的原因',max_length=200,blank=True,null=True)
    note = models.CharField(u'备注',max_length=200,blank=True,null=True)

    def __unicode__(self):
        return u'订单编号:'+self.orderID+u'  负责人:'+self.saleman.name
    class Meta:
        verbose_name = u'订单'
        verbose_name_plural = u'订单管理'

class Item(models.Model):
    name = models.CharField('项目名称',max_length=20)
    order = models.ForeignKey(Order)
    def __unicode__(self):
        return self.order.orderID
    class Meta:
        verbose_name = u'项目'
        verbose_name_plural = u'项目管理'

admin.site.register(Brand)
admin.site.register(Property)
admin.site.register(Gender)
admin.site.register(SaleMan)
admin.site.register(Status)
admin.site.register(Client)
admin.site.register(Order)
admin.site.register(Item)